#coding:utf-8
import os
import time
import sys
from xlsReader import *
def codeStatics(module = "new-ads-as",month = "01"):
    print "------start " + module +"------------"
    currentPath=os.path.abspath(sys.argv[0])
    currentPath=os.path.dirname(currentPath)+"/"

    print currentPath
    # currentPath = os.getcwd()
    # print currentPath
    result = os.system(currentPath + 'data/monthCodeStatics.sh '+ module + '> codeLine.txt')

    # output = result[1]
    # print output
    timeYear = time.strftime("%Y", time.localtime())
    key = timeYear + "-" + month
    if result == 0:
        monthCodeDic = readCodeLineFile()
        # print monthCodeDic
        if key in monthCodeDic:
            codeLineNum = monthCodeDic[key]
        else:
            print "monthCodeDic has no"+key
            print monthCodeDic
        # print codeLineNum
        return codeLineNum
    else:
        print "shell exe fail"
        return None
def readCodeLineFile():
    codeLineFile = "codeLine.txt"
    f = open(codeLineFile)
    line = f.readline()
    monthCodeDic = {}
    while line:
        # print line,
        codeMonthArr = line.strip().split(" ")
        # print codeMonthArr[0], codeMonthArr[1]
        monthCodeDic[codeMonthArr[1]] = codeMonthArr[0]
        line = f.readline()

    f.close()
    return  monthCodeDic
def getBugNum(module,month):
    currentPath=os.path.abspath(sys.argv[0])
    path=os.path.dirname(currentPath)+"/bugFile/"+"bug_2016"+month+".xls"
    return getBugNumByModule(module,path)
# codeStatics()
# print getBugNum("new-ads-as","07")